<?php


$db = new Mypdo();

$msgManager = new MessageManager($db);
$propriManager = new ProprietaireManager($db);


if($_POST){
    $err = true;
    ExceptionThrower::Start();
    try{
    $msgManager->reSendMsg($msgManager->getMsg($_POST['id_msg']));
    }catch (Exception $e){
        $err = false;

       echo '<p class="erreur">Erreur lors de l\'envois du message.<br/>
            Liaison au serveur smtp impossible.<br/>
            Veuillez contacter l\'administrateur si le problème persiste.</p>';

    }
    ExceptionThrower::Stop();

    if($err == true){
        $msgManager->delMsg($_POST['id_msg']);
    }

}
$list = $msgManager->getList();
?>
<h1>Messages non envoyer</h1>

<table class="tableau">
    <tr>
        <th>Propriétaire</th>
        <th>Email Emetteur</th>
        <th>Contenu</th>
    </tr>
    <?php foreach ($list as $value) {
        $propri = $propriManager->getPropri($value->getIdPropri());
        ?>
        <tr>
            <td><?php echo $propri->getNomPropri().' '.$propri->getPrenomPropri(); ?></td>
            <td><?php echo $value->getEmailExpeMsg(); ?></td>
            <td><?php echo $value->getComptenuMsg(); ?></td>
            <td>
                <form action="#" method="post">
                    <input type="hidden" name="id_msg" id="id_msg" value="<?php echo $value->getIdMsg(); ?>"/>
                    <input type="submit" value="Réenvoyer"/>
                </form>

            </td>
        </tr>
    <?php
    }
    ?>

</table>
